//
//  ActivityDetailTotalMemberCell.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 16/9/2.
//  Copyright © 2016年 陈区. All rights reserved.
//

#import "ActivityDetailTotalMemberCell.h"

@interface ActivityDetailTotalMemberCell ()

@property (nonatomic, retain) UILabel* memTitle;
//@property (nonatomic, retain) UIView* memberView;

@end

@implementation ActivityDetailTotalMemberCell

+ (instancetype)cellWithTableView:(UITableView*)tableView
{
    ActivityDetailTotalMemberCell* cell = [tableView dequeueReusableCellWithIdentifier:kActivityDetailTotalMemberCellIdentifier];

    if (cell == nil) {

        cell = [[ActivityDetailTotalMemberCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kActivityDetailTotalMemberCellIdentifier];
    }

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{

    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        [self setupUI];
    }
    return self;
}

- (void)setFrame:(CGRect)frame
{
    frame.size.width = [UIScreen mainScreen].bounds.size.width;
    [super setFrame:frame];
}

- (void)setupUI
{
    self.accessoryType = UITableViewCellAccessoryNone;
    self.selectionStyle = UITableViewCellSelectionStyleNone;

    NSInteger yPos = 0;
    self.memTitle = [[UILabel alloc] initWithFrame:CGRectMake(20, yPos + 9, 200, 20)];
    self.memTitle.font = [UIFont systemFontOfSize:FONT_DESCRIPTION_SIZE];
    self.memTitle.textColor = kColor_2;
    self.memTitle.tag = 2000;
    [self.contentView addSubview:self.memTitle];

    self.memberView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), 130)];
    self.memberView.tag = 3000;
    [self.contentView addSubview:self.memberView];

    UIImageView* line4ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 79.5, CGRectGetWidth(self.bounds), 0.5)];
    line4ImageView.image = [UIImage imageWithContentsOfFile:SEGPicName(@"line_640")];
    [self.contentView addSubview:line4ImageView];
}

- (void)setMemberArray:(NSArray<ActivityMemberModel*>*)memberArray
{
    self.memTitle.text = [NSString stringWithFormat:@"总共有%d人参加了此活动", (int)[memberArray count]];
    NSInteger xPos1 = 20;
    NSInteger i = 0;

    if ([memberArray count] > 0) {
        for (ActivityMemberModel* item in memberArray) {

            if (i <= 7) { //大于8个不再显示
                UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
                button.frame = CGRectMake(xPos1, 28, 32, 32);
                button.tag = i;
                UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
                imageView.layer.masksToBounds = YES;
                imageView.layer.cornerRadius = 3.f;
                imageView.image = [UIImage imageWithContentsOfFile:@""];
                [button addSubview:imageView];
                if (i == 7) {

                    UIView* tranView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
                    tranView.backgroundColor = [UIColor blackColor];
                    tranView.alpha = 0.6;
                    [imageView addSubview:tranView];

                    UILabel* more = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
                    more.textAlignment = NSTextAlignmentCenter;
                    more.text = @"更多";
                    more.font = [UIFont systemFontOfSize:FONT_DESCRIPTION_SIZE];
                    more.backgroundColor = [UIColor clearColor];
                    more.textColor = [UIColor whiteColor];
                    [button addSubview:more];
                }

                imageView.image = [UIImage imageWithContentsOfFile:SEGPicName(@"headimg60")];

                if (item.userIcon) {
                    //                    [SystemUtils saveServiceHeadImage:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kClientImageRootURL,item.userIcon]] aImageView:imageView defaultImage:@"headimg82"];

                    NSString* iconUrl = [NSString stringWithFormat:@"%@%@", kClientImageRootURL, item.userIcon];
                    [imageView setImageWithURL:[NSURL URLWithString:iconUrl] placeholderImage:[UIImage imageWithContentsOfFile:SEGPicName(@"headimg60")] options:SDWebImageLowPriority];
                }
                //                [button addTarget:self action:@selector(btnMemberButton:) forControlEvents:UIControlEventTouchUpInside];
                [self.memberView addSubview:button];
            }

            xPos1 += 37;
            i++;
        }
    }
}

@end
